package cn.arikeky.basic.controller;

import cn.arikeky.basic.anno.PreAuthorize;
import cn.arikeky.basic.dto.WechatLoginDto;
import cn.arikeky.basic.service.ILoginService;
import cn.arikeky.basic.util.AjaxResult;
import cn.arikeky.org.vo.LoginVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Map;

@RestController
@RequestMapping("/login")
public class LoginController {

    @Autowired
    private ILoginService loginService;

    // 后台登录
    @PostMapping("/account")
    public AjaxResult account(@RequestBody @Valid LoginVo loginVo){

        Map<String, Object> map = loginService.account(loginVo);
        return AjaxResult.me().success(map);
    }
    // 微信扫码
    @PostMapping("/wechat")
    public AjaxResult wechat(@RequestBody @Valid WechatLoginDto dto){
        return loginService.wechat(dto);
    }
    // 微信登录绑定
    @PostMapping("/wechat/binder")
    public AjaxResult wechatBinder(@RequestBody @Valid WechatLoginDto dto){
        Map<String, Object> stringObjectMap = loginService.wechatBbinder(dto);
        return AjaxResult.me().success(stringObjectMap);
    }
}
